﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Autofac;
using Conference.Command;
using Conference.CommandHandler;
using Conference.Common;
using Conference.Common.IocHelper;
using Conference.Common.Log;
using Conference.Common.Redis;
using Conference.Domain;
using Conference.Domain.Repository;
using Conference.EntityFrameworkCore;
using Conference.EntityFrameworkCore.RepositoryImpl;
using Conference.QueryService;
using Conference.QueryService.EventHandler;

namespace ConferenceWebApi
{
    /// <summary>
    /// 依赖注入服务
    /// </summary>
    public static class ConfigureContainerService
    {
        /// <summary>
        /// Builder
        /// </summary>
        /// <param name="builder"></param>
        public static void ConfigureContainerBuilder(this ContainerBuilder builder)
        {
            //注入ExceptionLessLogger服务
            builder.RegisterType<ExceptionLessLogger>().As<ILoggerHelper>();
            //注入简单的工作单元
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerLifetimeScope();
            //发送命令事件
            builder.RegisterType<CommandService>().As<ICommandService>().InstancePerLifetimeScope();
            //注入命令处理器（CAP的订阅注入必须在AddCap之前）;
            builder.RegisterType<ConferenceCommandHandler>().As<IConferenceCommandHandler>().InstancePerLifetimeScope(); ;
            //注入事件处理器（CAP的订阅注入必须在AddCap之前）
            builder.RegisterType<ConferenceEventHandler>().As<IConferenceEventHandler>().InstancePerLifetimeScope();
            //领域层发布事件
            builder.RegisterType<PublishDomainEventService>().As<IPublishDomainEventService>().InstancePerLifetimeScope();
            //注入泛型仓储基类         
            builder.RegisterAssembly("Conference.Domain", "Conference.EntityFrameworkCore");
            //builder.RegisterType<ConferenceRepository>().As<IConferenceRepository>().InstancePerLifetimeScope();
            //builder.RegisterType<CustomerRepository>().As<ICustomerRepository>().InstancePerLifetimeScope();
            builder.RegisterType<ConferenceQueryService>().As<IConferenceQueryService>().InstancePerLifetimeScope();
            //builder.RegisterAssemblyFluentValidation("ConferenceWebApi");
        }
    }
}
